<template>
  <div class="pending-send">
    <van-empty v-if="records.length===0" image="search" description="没有您搜索的订单" />

    <van-list
        v-else
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
    >
      <cell v-for="item in records"
            :record="item"
            :key="item.serialNo"
      ></cell>
    </van-list>
  </div>
</template>

<script>
import cell from "@/components/allOrders/cell";
import {GetOrdersList, GetPendingSend} from "@/request/api";

export default {
  data() {
    return {
      //请求参数
      current: 1,
      size: 10,
      keyword: "",
      total: 0,
      //传给cell的数据
      records: [],
      //van-list:
      loading: false,
      finished: false
    }
  },
  components: {
    cell
  },
  created() {
    GetPendingSend({
      current: this.current++,
      size: this.size,
      keyword: this.keyword
    }).then(res => {
      console.log("allorders res.data", res.data);
      //将数据push到records, records在template中使用
      res.data.records.forEach(item => {
        //存储所有records
        this.records.push(item);
      });
      //在这里数据请求成功后, 再把loading设置成false
      this.loading = false;
      //判断数据有没有全部请求完成
      if (this.records.length === this.total) {
        this.finished = true;
      }
    });
  },
  methods: {
    onLoad() {
      //每次处罚onload时loading都会被自动设置成true
      //请求数据
      GetPendingSend({
        current: this.current++,
        size: this.size,
        keyword: this.keyword
      }).then(res => {
        console.log("allorders res.data", res.data);
        //将数据push到records, records在template中使用
        res.data.records.forEach(item => {
          //存储所有records
          this.records.push(item);
        });
        //在这里数据请求成功后, 再把loading设置成false
        this.loading = false;
        //判断数据有没有全部请求完成
        if (this.records.length === this.total) {
          this.finished = true;
        }
      });
    }
  }



}
</script>

<style scoped>
.pending-send {
  padding-top: 50px;
  background-color: #cfcfcf;
}
</style>